<script>

count = 0;
http_request = new Array();


	function makeRequest(arg) {
		
		
		var obj = document.getElementById(arg);
		var list = document.getElementById(arg+'_list');
		
		if (obj.value != "") {
			var top = (document.body.clientHeight/2);
			var left = (document.body.clientWidth-200)/2;
			var img = document.getElementById('loader');
			img.style.top = top;
			img.style.left = left;
			img.style.visibility = 'visible';
	
			http_request.length = count+1;
			http_request[count] = new XMLHttpRequest();
	
			http_request[count].onreadystatechange = manageResult;
			http_request[count].open("GET", "http://localhost/conferences/ASE2008/ajax-manager.php?obj="+arg+"&key="+obj.value+"&count="+count, true);
			http_request[count].send(null);
			count++;
		}
		
	}
	

function manageResult() {
	
	var tutti_false = true;
	
	for (i=0; i<http_request.length; i++) {
		
		if (http_request[i] != false) {
			
			if (http_request[i].readyState == 4) {
				if (http_request[i].status == 200) {
					var xml = http_request[i].responseXML;
					var obj = xml.getElementsByTagName('obj').item(0).firstChild.data;
					var field = document.getElementById(obj);
					var objlist = document.getElementById(obj+'_list');
					var list = xml.getElementsByTagName('item');
					
					if (list.length > 0) {
						objlist.length = list.length;
						if (list.length < objlist.size) {
							objlist.size = list.length;
						}
					
						objlist.selectedIndex = 0;
						objlist.focus();
					
						for(i=0; i<list.length; i++) {
							objlist.options[i].value = list.item(i).firstChild.nextSibling.firstChild.data; 
							objlist.options[i].text = list.item(i).firstChild.nextSibling.nextSibling.nextSibling.firstChild.data;
						}
						field.value = objlist.options[0].text;
						objlist.style.visibility = 'visible';
					}
				}	else {
					alert("Error!");
				}
				
				http_request[i] = false;
			} else {
				tutti_false = false;
			}
			
		}
		
	}
	if (tutti_false == true) {
		var img = document.getElementById('loader');
		img.style.visibility = 'hidden';
	}
}

function my_update(arg) {
	var obj = document.getElementById(arg);
	var objlist = document.getElementById(arg+'_list');
	
	obj.value = objlist.options[objlist.selectedIndex].text;
	
}

function my_key(e) {
	alert(e.keyCode);	
}

function deselectlist(arg) {
	var objlist = document.getElementById(arg+'_list');
	
	objlist.style.visibility = 'hidden';
	
}
</script>
<img id="loader" src="img/ajax-loader.gif" style="position: absolute; visibility: hidden;">
Prova 
<div>
	<div style="width: 172px; height:20px; border-left: 1px solid #abadb3; border-top: 1px solid #abadb3; border-bottom: 1px solid #e3e9ef; border-right: 1px solid #e3e9ef;">
		<input onkeydown="my_key(event);" id="provincia" type="text" name="provincia" style="float: left; width: 150px; border: 0;">
		<img onClick="makeRequest('provincia');" style="border: 0px;" src="img/form/lista-valori2.png">
	</div>
	<select id="provincia_list" onChange="my_update('provincia');" onBlur="deselectlist('provincia');" name="provincia_list" style="width:174px; border-left: 1px solid #abadb3;border-bottom: 1px solid #abadb3;border-right: 1px solid #abadb3;border-top: 0px; visibility: hidden;" size="8">
	</select>
</div> 

				